import React from 'react';
import {Slider,Modal,Input, Button, message} from 'antd'
import InnovationEvaluationController from '@/services/InnovationProject/InnovationEvaluationController';
import QCProjectController from '@/services/QCProject/QCProjectController';
const {confirm} = Modal
const {TextArea} = Input
class EvaluationSubmit extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            rowData:props.rowData,
            resultEvaluationStep:props.resultEvaluationStep,
            userInfo:JSON.parse(sessionStorage.getItem('userInfo')),
            data:{},
            total:0
         };
    }
    componentDidMount(){
        this.props.onRef(this)
    }
    handleChange=(key,e)=>{
        let {data} = this.state
        data[key] = e
        this.getTotal(data)
        this.setState({
            data
        })
    }
    remarkChange=(e)=>{
        this.setState({
            remark:e.target.value
        })
    }
    getTotal=(data)=>{
        let total = 0
        Object.keys(data).forEach(item=>{
            total = total +data[item] 
        })
        this.setState({
            total
        })
    }
    submit=()=>{
        let {data,rowData,userInfo,remark,total,resultEvaluationStep} = this.state
        let that = this
        
        let params = {
            evaluateItem:JSON.stringify(data),
            scoreTotal:total,
            userName :userInfo.userName,
            name:userInfo.name,
            remark:remark,
            projectCode:rowData.projectCode,
            evaluateStep:resultEvaluationStep
        }
        confirm({
            title:'确认',
            content:'确定要提交吗？',
            onOk(){
                QCProjectController.evaluationSubmit(params).then(r=>{
                    if(r&&r.data===1){
                        message.success('提交成功')
                        that.props.onCancel()
                    }
                })
            }
        })
    }
    render() {
        const {resultEvaluationStep,total} = this.state
        return (
            <div>
                <div>
                    <div>
                        <strong>总分：</strong>
                        <span>{total}</span>
                    </div>
                    <div>
                        <strong>重要性：</strong>
                        <span><Slider max={30} min={0} tooltipVisible onChange={this.handleChange.bind(this,'重要性')}/></span>                        
                    </div>
                    <div>
                        <strong>创新性：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'创新性')}/></span>                        
                    </div>
                    <div>
                        <strong>程序：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'程序')}/></span>                        
                    </div>
                    <div>
                        <strong>方法：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'方法')}/></span>
                        
                    </div>
                    <div>
                        <strong>工具：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'工具')}/></span>
                    </div>
                    <div>
                        <strong>效果：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'效果')}/></span>
                    </div>
                    <div>
                        <strong>推广价值：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'推广价值')}/></span>
                    </div>
                    <div>
                        <strong>发表：</strong>
                        <span><Slider max={10} min={0} tooltipVisible onChange={this.handleChange.bind(this,'发表')}/></span>
                    </div>
                </div>
                <div>
                    <strong style={{verticalAlign:"top"}}>备注：</strong>
                    <TextArea onChange={this.remarkChange}/>
                </div>
               
            </div>
        );
    }
}

export default EvaluationSubmit;